package cn.yinyu.queue.module.ecg.config;

import cn.yinyu.queue.module.ecg.service.queue.QueueService;
import cn.yinyu.queue.module.ecg.service.room.RoomService;
import cn.yinyu.queue.module.infra.api.config.ConfigApi;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

import javax.annotation.Resource;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;

@Configuration
@EnableScheduling
public class DynamicSchedulingConfig implements SchedulingConfigurer {

    public static ScheduledTaskRegistrar static_scheduledTaskRegistrar;

    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        DynamicSchedulingConfig.static_scheduledTaskRegistrar = taskRegistrar;

        ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
        scheduledThreadPoolExecutor.setRemoveOnCancelPolicy(true);
        taskRegistrar.setScheduler(scheduledThreadPoolExecutor);
    }
}
